]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
workspaceAnimation: Split out BaseWorkspaceGroup
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 5 Dec 2025 08:25:30 +0000 (09:25 +0100)
committerMarge Bot <marge-bot@gnome.org>
Fri, 5 Dec 2025 22:34:23 +0000 (22:34 +0000)
Since we started to show DESKTOP windows as part of the background
during the workspace animation, we need to track both the windows
relevant for the monitor/workspace and DESKTOP windows.

We are about to split out the background handling into its own class.

To prepare for this, split out a BaseWorkspaceGroup class that handles the
basic "create clones of relevant windows and track them" functionality
common to both cases.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3995>

js/ui/workspaceAnimation.js

index 599f023c42dedf9775a86fe0fa5e5654caf2675b..0045a677bc2e7d0f3bef48e3a9c578ed2c23b3b7 100644 (file)
@@ -14,10 +14,10 @@ import * as Main from './main.js';
 export const WINDOW_ANIMATION_TIME = 250;
 export const WORKSPACE_SPACING = 100;
 
-export const WorkspaceGroup = GObject.registerClass(
-class WorkspaceGroup extends Clutter.Actor {
-    _init(workspace, monitor, movingWindow) {
-        super._init({
+export const BaseWorkspaceGroup = GObject.registerClass(
+class BaseWorkspaceGroup extends Clutter.Actor {
+    constructor(workspace, monitor) {
+        super({
             width: monitor.width,
             height: monitor.height,
             clip_to_allocation: true,
@@ -25,68 +25,20 @@ class WorkspaceGroup extends Clutter.Actor {
 
         this._workspace = workspace;
         this._monitor = monitor;
-        this._movingWindow = movingWindow;
         this._windowRecords = [];
 
-        if (this._workspace) {
-            this._background = new Meta.BackgroundGroup();
-
-            this.add_child(this._background);
-
-            this._bgManager = new Background.BackgroundManager({
-                container: this._background,
-                monitorIndex: this._monitor.index,
-                controlPosition: false,
-            });
-            this._createDesktopWindows();
-        }
-
+        this._createBackground();
         this._createWindows();
 
         this.connect('destroy', this._onDestroy.bind(this));
-        global.display.connectObject('restacked',
-            this._syncStacking.bind(this), this);
     }
 
     get workspace() {
         return this._workspace;
     }
 
-    _shouldShowWindow(window) {
-        if (!window.showing_on_its_workspace() || this._isDesktopWindow(window))
-            return false;
-
-        if (window.is_override_redirect())
-            return false;
-
-        if (!this._windowIsOnThisMonitor(window))
-            return false;
-
-        const isSticky =
-            window.is_on_all_workspaces() || window === this._movingWindow;
-
-        // No workspace means we should show windows that are on all workspaces
-        if (!this._workspace)
-            return isSticky;
-
-        // Otherwise only show windows that are (only) on that workspace
-        return !isSticky && window.located_on_workspace(this._workspace);
-    }
-
-    _syncStacking() {
-        const windowActors = global.get_window_actors().filter(w =>
-            this._shouldShowWindow(w.meta_window));
-
-        let lastRecord;
-        const bottomActor = this._background ?? null;
-
-        for (const windowActor of windowActors) {
-            const record = this._windowRecords.find(r => r.windowActor === windowActor);
-
-            this.set_child_above_sibling(record.clone,
-                lastRecord ? lastRecord.clone : bottomActor);
-            lastRecord = record;
-        }
+    _shouldShowWindow(_window) {
+        throw new GObject.NotImplementedError();
     }
 
     _isDesktopWindow(metaWindow) {
@@ -99,11 +51,7 @@ class WorkspaceGroup extends Clutter.Actor {
         return intersects;
     }
 
-    _createDesktopWindows() {
-        const desktopActors = global.get_window_actors().filter(w => {
-            return this._isDesktopWindow(w.meta_window) && this._windowIsOnThisMonitor(w.meta_window);
-        });
-        desktopActors.map(a => this._createClone(a)).forEach(clone => this._background.add_child(clone));
+    _createBackground() {
     }
 
     _createWindows() {
@@ -140,6 +88,81 @@ class WorkspaceGroup extends Clutter.Actor {
 
     _onDestroy() {
         this._removeWindows();
+    }
+});
+
+export const WorkspaceGroup = GObject.registerClass(
+class WorkspaceGroup extends BaseWorkspaceGroup {
+    constructor(workspace, monitor, movingWindow) {
+        super(workspace, monitor);
+
+        this._movingWindow = movingWindow;
+
+        global.display.connectObject('restacked',
+            () => this._syncStacking(), this);
+    }
+
+    _shouldShowWindow(window) {
+        if (!window.showing_on_its_workspace() || this._isDesktopWindow(window))
+            return false;
+
+        if (window.is_override_redirect())
+            return false;
+
+        if (!this._windowIsOnThisMonitor(window))
+            return false;
+
+        const isSticky =
+            window.is_on_all_workspaces() || window === this._movingWindow;
+
+        // No workspace means we should show windows that are on all workspaces
+        if (!this._workspace)
+            return isSticky;
+
+        // Otherwise only show windows that are (only) on that workspace
+        return !isSticky && window.located_on_workspace(this._workspace);
+    }
+
+    _syncStacking() {
+        const windowActors = global.get_window_actors().filter(w =>
+            this._shouldShowWindow(w.meta_window));
+
+        let lastRecord;
+        const bottomActor = this._background ?? null;
+
+        for (const windowActor of windowActors) {
+            const record = this._windowRecords.find(r => r.windowActor === windowActor);
+
+            this.set_child_above_sibling(record.clone,
+                lastRecord ? lastRecord.clone : bottomActor);
+            lastRecord = record;
+        }
+    }
+
+    _createBackground() {
+        if (!this._workspace)
+            return;
+
+        this._background = new Meta.BackgroundGroup();
+        this.add_child(this._background);
+
+        this._bgManager = new Background.BackgroundManager({
+            container: this._background,
+            monitorIndex: this._monitor.index,
+            controlPosition: false,
+        });
+        this._createDesktopWindows();
+    }
+
+    _createDesktopWindows() {
+        const desktopActors = global.get_window_actors().filter(w => {
+            return this._isDesktopWindow(w.meta_window) && this._windowIsOnThisMonitor(w.meta_window);
+        });
+        desktopActors.map(a => this._createClone(a)).forEach(clone => this._background.add_child(clone));
+    }
+
+    _onDestroy() {
+        super._onDestroy();
 
         if (this._workspace)
             this._bgManager.destroy();